<include file="Public:header" />
<include file="Public:leftside" />
<style type="text/css">
	.modal {
	    height: 600px;
	   
	}
	.modal-infp-style {
		width: 90%;
		margin: 10px auto;
	}
	
	.modal-infp-style table {
		width: 100%;
	}
	
	.modal-infp-style table tr td {
		border: 1px solid #e6e6e6;
		padding: 8px;
	}
	
	a:hover {
		cursor: pointer;
	}

	.pagination a{display: block;float: left;border-bottom-left-radius: 3px;border-top-left-radius: 3px;padding: 5px 10px;font-size: 12px;font-weight: 500;border-radius: 2px;}
	.pagination span{display: block;float: left;border-bottom-left-radius: 3px;border-top-left-radius: 3px;background-color: #fafafa;border: 1px solid #dddddd;padding: 5px 10px;font-size: 12px;font-weight: 500;border-radius: 2px;}

</style>
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i>
				<a href="/">首页</a>
			</li>
			<li class="active">会员等级管理</li>
		</ul>
	</div>
	<section class="scrollable wrapper">
		<!--<div class="row panel-body" style="padding-top:0px;">
			<a href="http://test.niushop.com/index.php/platform/member/memberlist.html" class="btn btn-sm btn-primary">会员列表</a>
			<a href="http://test.niushop.com/index.php/platform/member/memberlevellist.html" class="btn btn-sm btn-default">会员等级</a>
			<a href="http://test.niushop.com/index.php/platform/member/usercommissionwithdrawlist.html" class="btn btn-sm btn-default">会员提现</a>
			<a href="http://test.niushop.com/index.php/platform/member/pointlist.html" class="btn btn-sm btn-default">积分管理</a>
			<a href="http://test.niushop.com/index.php/platform/member/accountlist.html" class="btn btn-sm btn-default">余额管理</a>
			<a href="http://test.niushop.com/index.php/platform/member/weixinfanslist.html" class="btn btn-sm btn-default">粉丝列表</a>
		</div>-->
		<!-- 操作提示  start -->
		<!-- 操作提示  end -->
		<form action="__CONTROLLER__/index/" method="get">
		<div class="row padder-v">
			<div class="col-sm-9" style="width:65%;">
				<a href="{:U('Member/addgrade')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> 添加等级 </a>
			</div>
		</div>
		</form>
		<section class="panel panel-default">
			<div class="table-responsive">
				<table class="table table-striped b-t b-light text-sm">
					<thead>
						<tr>
							<th class="center">等级名称</th>
							<th class="center">售卡金额</th>
							<th class="center">最低积分</th>
							<th class="center">消费折扣设置</th>
							<th class="center">消费积分设置</th>
							<th class="center">代言红包设置</th>
							<th class="center">操作</th>
						</tr>
					</thead>
					<tbody id="list">
						<foreach name="grade_list" item="v">
							<tr align="center">
								<td class="tal">{$v.gradeName}</td>
								<td class="tal">{$v.money}</td>
								<td class="tal">{$v.min_integral}</td>
								<td class="tal">{$v.discount}</td>
								<td class="tal">{$v.points}</td>
								<td class="tal">{$v.daiyan}</td>
								<td>
									<a onclick="modify_grade({$v.id})">修改</a>&nbsp;
									<a href="{:U('grade_del')}" data-id="{$v.id}"  class="js-ajax-delete" >删除</a>
							</tr>
						</foreach>
					</tbody>
				</table>
			</div>

			<footer class="panel-footer">
				<div class="row" id="page">
				<div class="col-sm-2 text-center">
						<small class="text-muted inline m-tb-8">总计 <span id="total_count_num">{$count}</span>个记录</small>
					</div>
					<div class="col-sm-5 text-right text-center-xs">
						<ul class="pagination pagination-sm m-t-none m-b-none">
							{$page}
						</ul>
					</div>
				</div>
			</footer>

		</section>

		<script type="text/javascript">
            $('.js-ajax-delete').on('click', function (e) {
                e.preventDefault();
                var $_this = this,
                    $this = $($_this),
                    href = $this.prop('href'),
                    id = $this.data('id');
                layer.confirm('确定要删除吗？', {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        url:href,
                        type:"POST",
                        dataType:'json',
                        data: {
                            'id': id,
                        },
                        success:function (json) {
                            console.log(json.data.post);
                            var status = 1;
                            if(!json.status || json.status != 1) status = 3;
                            if(status == 1){
                                layer.closeAll();
                            }
                            layer.alert(json.message,function(){
                                if(status != 1){
                                    layer.closeAll();
                                }
                                if(json.data.result && json.data.result.redirect_url){
                                    window.location.href = json.data.result.redirect_url;
                                }else if(json.data.url ){
                                    window.location.href = json.data.url;
                                }
                            });
                        }
                    });
                });

            });
			//修改等级弹出
			function modify_grade(gradeId) {
				var id = parseInt(gradeId);
				$("#modify_grade").modal("show");
				$.ajax({
					type: "post",
					url: "{:U('Member/getgradedetail')}",
					data: {
						'id': id,
					},
					success: function(json) {
                        data= JSON.parse(json);
                        $datas=data.data;
						$("#grade_id").val($datas.id);
						$("#gradeName").val($datas.gradeName);
						$("#money").val($datas.money);
                        $("#min_integral").val($datas.min_integral);
                        $("#discount").val($datas.discount);
                        $("#points").val($datas.points);
                        $("#daiyan").val($datas.daiyan);
					}
				});
			}
			
			function modifyGrade(){
				var grade_id = $("#grade_id").val();
				var gradeName = $("#gradeName").val();
				var money = $("#money").val();
                var min_integral = $("#min_integral").val();
                var discount = $("#discount").val();
                var points = $("#points").val();
                var daiyan = $("#daiyan").val();
                if(grade_id== '') {
                    layer.msg('等级ID不能为空！')
                    return false;
                }
                if(gradeName== '') {
                    layer.msg('等级名称不能为空！')
                    return false;
                }
                if(money== '') {
                    layer.msg('销售金额不能为空！')
                    return false;
                }
                if(min_integral== '') {
                    layer.msg('所需最低积分不能为空！')
                    return false;
                }
                if(discount== '') {
                    layer.msg('消费折扣不能为空！')
                    return false;
                }
                if(points== '') {
                    layer.msg('消费积分不能为空！')
                    return false;
                }
				$.ajax({
					type : "post",
					url : "{:U('Member/update_grade')}",
					data : {
						'id':grade_id,
						'gradeName' : gradeName,
						'money' : money,
						'min_integral' : min_integral,
						'discount' : discount,
                        'points' : points,
                        'daiyan' : daiyan
					},
					success : function(data) {
                        json= JSON.parse(data);
                        if(json.status == 0) {
                            layer.msg('无数据更新！')
                        }
                        if(json.status == 1) {
                            layer.msg('修改成功！');
                            setTimeout("location.reload()",1000);
                        }
					}
				});
			}

		</script>
		<!-- 修改会员 -->
		<div class="modal" id="modify_grade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
						<h4 class="modal-title" id="myModalLabel">编辑会员等级</h4>
					</div>
					<div class="modal-body">
						<div class="modal-infp-style" style="height:360px;overflow:auto;">
							<table class="modal-tab">
								<tbody>
									<tr>
										<td style="width:30%;"><span class="required">*</span>会员等级名称</td>
										<td colspan="3">
											<input type="text" class="form-control" datatype="required" data="会员等级名称" id="gradeName" name="gradeName" required="" >
										</td>
									</tr>
									<tr>
										<td style="width:30%;"><span class="required">*</span>售卡金额</td>
										<td colspan="3">
											<input type="text" class="form-control" datatype="required"  data="售卡金额" id="money" name="money" required="" value="" >
										</td>
									</tr>
									<tr>
										<td style="width:30%;"><span class="required">*</span>最低积分</td>
										<td colspan="3">
											<input type="text" class="form-control" datatype="required" data="最低积分" id="min_integral" name="min_integral" required="" value="">
										</td>
									</tr>
									<tr>
										<td style="width:30%;"><span class="required">*</span>消费折扣设置</td>
										<td colspan="3">
											<input type="text" class="form-control" datatype="required" data="消费折扣设置" id="discount" name="discount" required="" value="">
										</td>
									</tr>
									<tr>
										<td style="width:30%;"><span class="required">*</span>消费积分设置</td>
										<td colspan="3">
											<input type="text" class="form-control" datatype="required" data="消费积分设置"id="points"  name="points" required="" value="">
										</td>
									</tr>
									<tr>
										<td style="width:30%;"><span class="required">*</span>代言红包设置</td>
										<td colspan="3">
											<input type="text" class="form-control" datatype="required" data="代言红包设置" id="daiyan" name="daiyan" required="" value="">
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>

					<div class="modal-footer">
						<input type="hidden" id="grade_id">
						<button class="btn btn-info" onclick="modifyGrade()" id="butSubmit" style="display:inline-block;">保存</button>
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>

		</div>

	</section>
</div>

<include file="Public:footer" />